import logging
import threading

from msg_handler_impl.handler import SingleMsgHandlerBase

logger = logging.getLogger()

HANDLERS: list[SingleMsgHandlerBase] = []


def handle(msg: dict, ctx: threading.local, *args, **kwargs):
    try:
        for handler in HANDLERS:
            if handler.can_handle(msg):
                handler.handle(msg, ctx)
    except Exception as e:
        logger.exception(e)
